package com.zk.controller;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zk.bcutil.DBUtil;
import com.zk.service.OrganizationService;

@Controller
@RequestMapping("/get")
public class GetOrgInfoController {

	@Autowired
	private OrganizationService organizationService;
	

	@RequestMapping("/organization")  
	public @ResponseBody Map<String,Object> login(HttpServletRequest request,HttpServletResponse response) throws IOException{  
	        System.out.println(request.getParameter("email")+"### " + request.getParameter("password"));  
	        Map<String,Object> map = new HashMap<String,Object>();  
	        DBUtil s = new DBUtil();
	        ResultSet rs;
			rs = s.Query("select * from logintable where loginname = "+"'"+request.getParameter("email")+"'" +"and password = " +"'"+ request.getParameter("password")+"'" );
			try {
				if(rs.next()){
					System.out.println("结果集不为空!");
					map.put("msg", "成功");
				}else{
					System.out.println("结果集为空！");
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				s.close();
			} 
	       
	        return map;  
	    }
	//changeValue
	@RequestMapping("/changeValue")  
	public @ResponseBody Map<String,Object> changeValue(HttpServletRequest request,HttpServletResponse response) throws IOException{  
	        String ckid = request.getParameter("ckid");
	        String value = request.getParameter("value");
	        if(!"".equals(value)&&null!=value){
	        	if("1".equals(value)){
	        		value = "0";
	        	}else{
	        		value = "1";
	        	}
	        }
	        Map<String,Object> map = new HashMap<String,Object>();  
	        DBUtil s = new DBUtil();
	        int result = 0;
	        //UPDATE CHECKINTERFACE SET MARK = "+value+" WHERE CKID = "+ckid+";
	        result = s.update("UPDATE CHECKINTERFACE SET MARK = "+"'"+value+"'" +"WHERE CKID = " +"'"+ ckid+"'" );
			if(result>0){
                System.out.println("操作成功");
                map.put("msg", "成功");
            }else{
                System.out.println("操作失败");
                map.put("msg", "失败");
            }
			s.close();
	       
	        return map;  
	    }
	
	@RequestMapping("/data")  
	public @ResponseBody List<Map<String,Object>> data(HttpServletRequest request,HttpServletResponse response) throws IOException{  

		System.out.println(1);
		System.out.println(1);
		System.out.println(1);
		List<Map<String,Object>> mapList =  new ArrayList<Map<String, Object>>();
		  
		
	        DBUtil s = new DBUtil();
	        ResultSet rs;
			rs = s.Query("select CKID,SYSNAME, MARK, BELONG, JC from checkinterface where 1 = 1" );
			
			try {
				while(rs.next()){
					Map<String,Object> map = new HashMap<String,Object>();
					map.put("ckid", rs.getString("CKID"));
					map.put("name", rs.getString("SYSNAME"));
					map.put("mark", rs.getString("MARK"));
					map.put("belong", rs.getString("BELONG"));
					map.put("jc", rs.getString("JC"));
					//map.put(rs.getString("JC"), js.toString());
					mapList.add(map);
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				s.close();
			} 
	       
	        return mapList;  
	        
	        /**
	         * 
	         */
	    }
}

/**
 * 	System.out.println(1);
		System.out.println(1);
		System.out.println(1);
		List<Map<String,Object>> mapList =  new ArrayList<Map<String, Object>>();
		  
		JSONObject js = new JSONObject();
	        DBUtil s = new DBUtil();
	        ResultSet rs;
			rs = s.Query("select SYSNAME, MARK from checkinterface where 1 = 1" );
			try {
				while(rs.next()){
					//js.put(key, value)

					Map<String,Object> map = new HashMap<String,Object>();
					map.put(rs.getString("SYSNAME"), rs.getString("MARK"));
					mapList.add(map);
				}
			} catch (SQLException e) {

				e.printStackTrace();
			}finally{
				s.close();
			} 
	       
	        return mapList;  
*/